package openGL.ES;

public class Vector2 
{
	private float x = 0;
	private float y = 0;
	
	/**
	 * Creates a new Vector2 object
	 * @param x x coordinate of the Vector2
	 * @param y y coordinate of the Vector2
	 */
	public Vector2(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Gets the x value of the Vector2
	 * @return The x value of the Vector2
	 */
	public float getX()
	{
		return x;
	}
	
	/**
	 * Sets the x value of the Vector2
	 * @param value The new x value to use
	 */
	public void setX(float value)
	{
		x = value;
	}
	
	/**
	 * Gets the y value of the Vector2
	 * @return The y value of the Vector2
	 */
	public float getY()
	{
		return y;
	}
	
	/**
	 * Sets the y value of the Vector2
	 * @param value The y value of the Vector2
	 */
	public void setY(float value)
	{
		y = value;
	}
	
	/**
	 * Adds a Vector2 to this Vector2, providing a new Vector2 as the result
	 * @param other Vector2 to add to this Vector2
	 * @return A new Vector2 taken from adding the Vectors together
	 */
	public Vector2 addVector(Vector2 other)
	{
		Vector2 vec = new Vector2(x, y);
		vec.x = x + other.x;
		vec.y = y + other.y;
		return vec;
	}
	
	/**
	 * Subtracts a Vector2 from this Vector2, providing a new Vector2 as the result
	 * @param other Vector2 to subtract from this Vector2
	 * @return A new Vector2 taken from subtracting the other Vector2 from this one
	 */
	public Vector2 subVector(Vector2 other)
	{
		Vector2 vec = new Vector2(x, y);
		vec.x = x - other.x;
		vec.y = y - other.y;
		return vec;
	}
	
	/**
	 * Scales (multiplies) the Vector2 by a value
	 * @param value Value to scale the Vector2 by
	 * @return A new Vector2 taken from scaling the Vector2 by the value
	 */
	public Vector2 scaleVector(float value)
	{
		Vector2 vec = new Vector2(x, y);
		vec.x = x * value;
		vec.y = y * value;
		return vec;
	}
	
	/**
	 * Divides the Vector2 by a value
	 * @param value Value to divide the Vector2 by
	 * @return A new Vector2 taken from dividing the Vector2 by the value
	 */
	public Vector2 divideVector(float value)
	{
		Vector2 vec = new Vector2(x, y);
		vec.x = x / value;
		vec.y = y / value;
		return vec;
	}
	
	/**
	 * Compares another Vector2 against this Vector2 for equality
	 * @param other Vector2 to compare against
	 * @return True if the Vectors are equal (both x and y), false otherwise
	 */
	public boolean equals(Vector2 other)
	{
		if (other.x == x && other.y == y)
			return true;
		return false;
	}
	
	/**
	 * Gets the length of the Vector2
	 * @return The length of the Vector2
	 */
	public float length()
	{
		return (float)(Math.sqrt((x * x) + (y * y)));
	}
}